
import fs from 'fs'
import typescript from "@rollup/plugin-typescript";
import commonjs from "@rollup/plugin-commonjs";
import { terser } from 'rollup-plugin-terser'
import dts from 'rollup-plugin-dts';
import strip from "@rollup/plugin-strip";
import filesize from "rollup-plugin-filesize";
import deletePlugin from 'rollup-plugin-delete';

const packageJson = JSON.parse(fs.readFileSync("./package.json", "utf8")); 
const pkgName = packageJson.umdPackageName;

const external = ['os', 'process', 'tty', 'stream', 'buffer', 'events', 'util', 'fs'];

const tsconfig = './tsconfig.json'
const input = 'tool/index.ts';

/** @type {import('rollup').RollupOptions} */
export default [
    {
        input,
        output: [
            {
                file: 'dist/index.min.js',
                format: 'umd',
                exports: 'named',
                name: pkgName,
                sourcemap: false
            }
        ],
        external,
        plugins: [
            typescript({ tsconfig }),
            commonjs(),
            terser(),
            strip(),
            filesize(),
            deletePlugin({ targets: ['dist/*'] })
        ]
    },
    {
        input,
        output: [
            {
                file: 'dist/index.min.mjs',
                format: 'es',
                exports: undefined,
                sourcemap: false
            }
        ],
        external,
        plugins: [
            commonjs(),
            terser(),
            strip(),
            filesize(),
            typescript({ tsconfig }),
        ]
    },
    {
        input,
        output: [
            {
                file: 'dist/esyTools.min.js',
                format: 'iife',
                name: pkgName,
                sourcemap: false
            }
        ],
        external,
        plugins: [
            commonjs(),
            terser(),
            strip(),
            filesize(),
            typescript({ tsconfig }),
        ]
    },
    {
        input,
        output: [
            {
                dir: 'dist',
                format: 'es',
            }
        ],
        external,
        plugins: [dts()],
    },
];